package com.noahplat.sms.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.sms.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;


/**
 * 作者：李景星
 * 描述：短信平台接口
 * 时间：2021-01-27
 */
@RequestMapping("/api/sms")
@RestController
@Validated
public class SmsController {

    @Autowired
    private SmsService smsService;

    /**
     * 短信发送注册验证吗
     * @name 李景星
     * @param phone
     * @return
     */
    @GetMapping("/sendRegCode")
    public Result sendRegCode(@NotEmpty(message = "手机号不能为空")  String phone){
        return smsService.sendRegCode(phone);
    }

    /**
     * 找回密码发送短信验证码
     * @name 李景星
     * @param phone
     * @return
     */
    @GetMapping("/sendAPassCode")
    public Result sendAPassCode(@NotNull(message = "系统ID不能为空 ") @Min(value = 1, message = "系统Id不能为空")Long stid,@NotEmpty(message = "手机号不能为空") String phone){
        return smsService.sendAPassCode(stid,phone);
    }

    /**
     * 修改手机号发送短信验证码
     * @name 宋彦磊
     * @param phone
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-sms:SmsController:sendUpdateCode')")
    @GetMapping("/sendUpdateCode")
    public Result sendUpdateCode(@NotEmpty(message = "手机号不能为空") String phone){
        return smsService.sendUpdateCode(phone);
    }
}
